"""
字典：dict
是以键值对来表示
"""



#创建一个dict

# person = {"name":"Allen","age":"18"}   # name & age 是key, Allen & 18 是value
# print(type(person))
# print(person)

#通过zip的格式来创建字典
# k = ["name","age","job"]
# v = ['Allen','18','teacher']
# d = dict(zip(k,v))
# print(d)

#通过fromkeys方法来创建一个值为空的字典
# a = dict.fromkeys(['name','age','job'])
# print(a)

# 通过get的方法取出对应的value
# a_dict = {"name":"Allen","age":"18"}
# print(a_dict.get('name'))   # Allen

#通过[]方法来取相应的values值
# print(a_dict["age"])        #18

#列出字典当中所有的键值对
# items
# a_dict = {"name":"Allen","age":"18"}
# print(a_dict.items())   #列表套元组的形式返回value

#列出字典中所有的键
# keys
# a_dict = {"name":"Allen","age":"18"}
# print(a_dict.keys())    # 将dict中的所有的key进行返回


#列出字典中所有的值
# values
# a_dict = {"name":"Allen","age":"18"}
# print(a_dict.values())   # dict_values(['Allen', '18'])


# #通过内置函数来返回字典中的键值对的个数
# a_dict = {"name":"Allen","age":"18"}
# print(len(a_dict))   #  2

# if 'name' in a_dict:
#     print("存在")
# else:
#     print("不存在")


#使用update更新字典
# a_dict = {"name":"Allen","age":"18"}
# b_dict = {"name":"Allen1","age":"19"}
# a_dict.update(b_dict)   # {'name': 'Allen1', 'age': '19'}
# print(a_dict)

#删除 pop: 指定删除
# a_dict = {"name":"Allen","age":"18"}
#
# # a_dict.pop('name')   #指定删除key
# # print(a_dict)
#
# #通过del删除键值对
# del a_dict["age"]
# print(a_dict)
#清空字典使用clear
# a_dict.clear()
# print(a_dict)



# dict_info = {"name":"张三","age":18,"address":"沈阳","phone":"12345678910"}

# for key in dict_info.keys():
#     print(key)

# for values in dict_info.values():
#     print(values)

# for keys,values in dict_info.items():
#     print(f"keys的值是{keys}，values的值是{values}")
